using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }

    private void LoadData()
    {
        tbSanPhamEntities.tbSanPhanEntitiesCollection spCollection = tbSanPhamBUS.GetAll();
        Repeater1.DataSource = spCollection;
        Repeater1.DataBind();
    }

    //protected void Pager_Command(object sender, CommandEventArgs e)
    //{
    //    Pager.CurrentIndex = int.Parse(e.CommandArgument.ToString());
    //    LoadData();
    //}
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
            e.Item.ItemType == ListItemType.Item)
        {
            tbSanPhamEntities sp = (tbSanPhamEntities)e.Item.DataItem;
            HyperLink hyp_sp = (HyperLink)e.Item.FindControl("hyp_sp");
            //Literal lit_idsp = (Literal)e.Item.FindControl("lit_idsp");
            Image img_hinhanh = (Image)e.Item.FindControl("img_hinhanh");
            //Literal lit_mota = (Literal)e.Item.FindControl("lit_mota");
            HyperLink hyl_chitiet = (HyperLink)e.Item.FindControl("hyl_chitiet");
            hyp_sp.Text = sp.TenSP;
            //lit_idsp.Text = sp.MaSP.ToString();

            int IDH = tbHinhAnhBUS.imageFirst(int.Parse(sp.MaSP.ToString()));
            tbHinhAnhEntities hh = tbHinhAnhBUS.GetByID(IDH);

            img_hinhanh.ImageUrl = "~/Photos/Thumb/" + hh.HinhAnh.ToString();

            hyp_sp.NavigateUrl = "ChiTiet.aspx?id= " + sp.MaSP.ToString();
            hyl_chitiet.NavigateUrl = "ChiTiet.aspx?id= " + sp.MaSP.ToString();

        }

    }
}
